﻿using Microsoft.Toolkit.Uwp.Notifications;

namespace MeiWinForms.comm;

public static class Notify
{
    public static void Subscribe(string eventKey, Action action)
    {
        ToastNotificationManagerCompat.OnActivated += e =>
        {
            if (e.Argument == eventKey) // 检查按钮的参数
            {
                action.Invoke();
            }
        };
    }

    public static void ShowNotification(string text, string eventKey = "")
    {
        Output.WriteOutput("[Notify] " + text);
        ToastContentBuilder? builder = new ToastContentBuilder().AddText(text);
        if (!string.IsNullOrEmpty(eventKey))
        {
            builder.AddButton("确认", ToastActivationType.Foreground, eventKey);
        }

        builder.Show();
    }
}